package com.pbdatabase.core.main;

import com.pbdatabase.core.indexer.InMemoryIndexer;
import com.pbdatabase.core.indexer.Indexer;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class IndexProcessor {
	private static Logger _logger = Logger.getLogger(IndexProcessor.class);

	private static IndexProcessor _instance;

	public synchronized static IndexProcessor getInstance() {
		if (null == _instance) {
			_instance = new IndexProcessor();
		}
		return _instance;
	}

	private Map<String, Indexer> indexes;

	private IndexProcessor() {
		indexes = new HashMap<String, Indexer>();
	}

	public Indexer getIndexer(String protoName) {
		return indexes.get(protoName);
	}

	public void addIndexer(String protoName) {
		Indexer indexer = new InMemoryIndexer();
		indexer.initialize(protoName);
		if (indexes.containsKey(protoName))
			indexes.remove(protoName);
		indexes.put(protoName, indexer);
	}
}
